package com.example.springboot01.util;

// bit map
// bit 0 1

// byte = 8 bit

// byte []

public class CustomerFilter {

    private byte[] map;

    private int size;

    public CustomerFilter(int size) {
        this.size = size;
        this.map = new byte[size / 8];
    }

    public void add(Object o) {
        final int i = o.hashCode();
        final int index = i / 8;
        final int bitIndex = i % 8;
        //  0 | 0 = 0  0 | 1 = 1
        this.map[index] = (byte) (this.map[index] | (1 << bitIndex));
        System.out.println(this.map[index]);
    }

    public boolean contains(Object o) {
        final int i = o.hashCode();
        final int index = i / 8;
        final int bitIndex = i % 8;
        System.out.println(this.map[index]);
        return (this.map[index] & (1 << bitIndex)) != 0;
    }

    public static void main(String[] args) {
        final CustomerFilter filter = new CustomerFilter(8);
        System.out.println(filter.contains(7));
        filter.add(7);
        System.out.println(filter.contains(7));
    }
}
